#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int N=300050;
struct node{
    long long i,c;
    bool operator <(const node&a)const{
        return c<a.c;
    }
}p[N];
int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld",&p[i].c);
        p[i].i=i;
    }
    long long ans=0;
    priority_queue<node> q;
    for(int i=1;i<=k;i++){
        q.push(p[i]);
    }
    for(int i=k+1;i<=k+n;i++){
        if(i<=n){
            q.push(p[i]);
        }
        node t=q.top();
        q.pop();
        ans+=(i-t.i)*t.c;
        p[t.i].i=i;
    }
    printf("%lld\n",ans);
    for(int i=1;i<n;i++){
        printf("%d ",p[i].i);
    }
    printf("%d\n",p[n].i);
    return 0;
}